<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY 杭州博也网络科技有限公司
// |-----------------------------------------------------------------------------------
// | Author: 青 <99701759@qq.com>
// | Copyright (c) 2013-2016, http://www.itboye.com. All Rights Reserved.
// |-----------------------------------------------------------------------------------

namespace Home\Controller;
use Shop\Api\AddressApi;
use Think\Controller;
use Ucenter\Api\UserLogApi;
use Weixin\Api\WxuserApi;
use Shop\Api\WithdrawApi;
class AccountController extends HomeController {

    /*
     * 申请提现
     * */
    public function apply_money(){
        if(IS_POST){
            $userinfomap['id'] = $this->userinfo['id'];
            $userinfores =  apiCall(WxuserApi::GET_INFO, array($userinfomap));
            if($userinfores['status']){
                $residue = bcadd($userinfores['info']['money'],2) - (bcadd(I('money'),2));
                if($residue >= 0){
                    $withdraw['money'] = I('money');
                }else{
                    $this->error('对不起您的账户并没有这么多余额',U('Account/index'));
                }
            }
            $withdraw['uid'] = $this->userinfo['id'];
            $withdraw['create_time'] = time();
            $withdraw['update_time'] = time();
            $withdraw['account_name'] = I('account_name');
            $withdraw['cash_account'] = I('account');
            $withdraw['bank_branch'] = '支付宝';
            $withdraw['status'] = 0;
            $withdrawres = apiCall(WithdrawApi::ADD,array($withdraw));
            if($withdrawres['status']){
                //提现申请申请成功后将Wuser中的钱减去
                $moneymap['money'] = $residue;
                $userinfores =  apiCall(WxuserApi::SAVE, array($userinfomap,$moneymap));
                if($userinfores['status']){
                    $this->success('申请成功',U('UserCenter/apply_money'));
                }
            }else{
                $this->error('申请失败',U('Account/index'));
            }

        }else{
            $userinfomap['id'] = $this->userinfo['id'];
            $userinfores =  apiCall(WxuserApi::GET_INFO, array($userinfomap));
            if($userinfores['status']){
                $this->assign('money',$userinfores['info']['money']);
            }
            $this->display();
        }
    }

    /*
     *增加储值
     * */
    public function add_store(){

        $this->display();
    }

    /*
     * 微信支付
     * */
    public function pay_store(){

        $this->display();
    }

}